package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.pojo.Card;
import com.woniu.pojo.Member;
import com.woniu.pojo.Receiver;
import com.woniu.service.IMemberService;
import com.woniu.vo.MemberQueryVo;
import com.woniu.vo.QueryCardVo;
import com.woniu.vo.QueryMemberLevelCoachVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xie
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/member")
@Api(tags = "会员管理")
public class MemberController extends BaseController{

    @Autowired
    private IMemberService service;

    @PostMapping("/search/{currentPage}/{pageSize}")
    @ApiOperation("分页通过条件查询")
    public Result queryByItemInPage(@PathVariable(required = false) int currentPage,
                                    @PathVariable(required = false) int pageSize,
                                    @RequestBody MemberQueryVo vo) {
        PageResult result=service.queryByItemInPage(currentPage,pageSize,vo);
        return toDataResult(result);
    }

    @GetMapping("/{id}")
    @ApiOperation("通过id查找")
    public Result queryMemberLevelCoachById(@PathVariable String id){
        Member me = service.getById(id);
        return toDataResult(me);
    }

    @GetMapping("/card/{id}")
    @ApiOperation("通过会员id查找会员卡信息")
    public Result queryCardById(@PathVariable String id){
        List<QueryCardVo> card=service.queryCardById(id);
        return toDataResult(card);
    }

    @PutMapping
    @ApiOperation("修改")
    public Result modify(@RequestBody Member member){
        boolean flag = service.updateById(member);
        return toResult(flag);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("通过id删除")
    public Result delete(@PathVariable String id){
        int row = service.delete(id);
        return toResult(row);
    }



}
